<template>
  <div>
    <ul>
      <li
        v-for="(item,index) in headerList"
        :key="item.id"
      >
        <router-link :to="{ name: item.name }" tag="div"
                     class="link"
                     @click.native="switchRouter(index)"
        >
          <svg-icon :icon-class="item.icon" /> <br>
          {{ item.title }}
        </router-link>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  data() {
    return {
      headerList: [
        { id: '1', name: 'home', title: '首页', icon: 'home' },
        { id: '2', name: 'amusement', title: '游乐园', icon: 'amusement' },
        { id: '3', name: 'official', title: '官方', icon: 'official' },
        { id: '4', name: 'square', title: '杠题广场', icon: 'square' },
        { id: '5', name: 'personal', title: '个人中心', icon: 'personal' }
      ]
    };
  },
  mounted() {
    const link = document.getElementsByClassName('link');
    link.forEach((item, index) => {
      if (item.className.indexOf('is-active') !== -1) {
        this.switchRouter(index);
      }
    });
  },
  methods: {
    switchRouter(index) {
      this.headerList.forEach(item => {
        if (item.icon.indexOf('Active') !== -1) {
          item.icon = item.name;
        }
      });
      this.headerList[index].icon += 'Active';
      this.$emit('getTitle', this.headerList[index].title);
    }
  }
};
</script>
<style lang="scss" scoped>
ul{
  border-top: 1px solid gray;
  width: 100%;
  height: 100%;
  position: 0px;
  margin: 0px;
  li{
    margin-top: 2px;
    float: left;
    width: 20%;
    font-size: 14px;
    text-align: center;
    color: #5e5e5e;
    .svg-icon{
      width: 25px;
      height: 25px;
    }
  }
  .is-active{
    color:#303133;
    font-weight: 600;
  }
}
</style>
